home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / g_quake / progs106.zip / ITEMS.QC < prev    next >
Text File  |  1996-09-26  |  30KB  |  1,381 lines

  1. void() W_SetCurrentAmmo;
  2. /* ALL LIGHTS SHOULD BE 0 1 0 IN COLOR ALL OTHER ITEMS SHOULD
  3. BE .8 .3 .4 IN COLOR */
  4.  
  5.  
  6. void() SUB_regen =
  7. {
  8.     self.model = self.mdl;        // restore original model
  9.     self.solid = SOLID_TRIGGER;    // allow it to be touched again
  10.     sound (self, CHAN_VOICE, "items/itembk2.wav", 1, ATTN_NORM);    // play respawn sound
  11.     setorigin (self, self.origin);
  12. };
  13.  
  14.  
  15.  
  16. /*QUAKED noclass (0 0 0) (-8 -8 -8) (8 8 8)
  17. prints a warning message when spawned
  18. */
  19. void() noclass =
  20. {
  21.     dprint ("noclass spawned at");
  22.     dprint (vtos(self.origin));
  23.     dprint ("\n");
  24.     remove (self);
  25. };
  26.  
  27.  
  28.  
  29. /*
  30. ============
  31. PlaceItem
  32.  
  33. plants the object on the floor
  34. ============
  35. */
  36. void() PlaceItem =
  37. {
  38.     local float    oldz;
  39.  
  40.     self.mdl = self.model;        // so it can be restored on respawn
  41.     self.flags = FL_ITEM;        // make extra wide
  42.     self.solid = SOLID_TRIGGER;
  43.     self.movetype = MOVETYPE_TOSS;    
  44.     self.velocity = '0 0 0';
  45.     self.origin_z = self.origin_z + 6;
  46.     oldz = self.origin_z;
  47.     if (!droptofloor())
  48.     {
  49.         dprint ("Bonus item fell out of level at ");
  50.         dprint (vtos(self.origin));
  51.         dprint ("\n");
  52.         remove(self);
  53.         return;
  54.     }
  55. };
  56.  
  57. /*
  58. ============
  59. StartItem
  60.  
  61. Sets the clipping size and plants the object on the floor
  62. ============
  63. */
  64. void() StartItem =
  65. {
  66.     self.nextthink = time + 0.2;    // items start after other solids
  67.     self.think = PlaceItem;
  68. };
  69.  
  70. /*
  71. =========================================================================
  72.  
  73. HEALTH BOX
  74.  
  75. =========================================================================
  76. */
  77. //
  78. // T_Heal: add health to an entity, limiting health to max_health
  79. // "ignore" will ignore max_health limit
  80. //
  81. float (entity e, float healamount, float ignore) T_Heal =
  82. {
  83.     if (e.health <= 0)
  84.         return 0;
  85.     if ((!ignore) && (e.health >= other.max_health))
  86.         return 0;
  87.     healamount = ceil(healamount);
  88.  
  89.     e.health = e.health + healamount;
  90.     if ((!ignore) && (e.health >= other.max_health))
  91.         e.health = other.max_health;
  92.         
  93.     if (e.health > 250)
  94.         e.health = 250;
  95.     return 1;
  96. };
  97.  
  98. /*QUAKED item_health (.3 .3 1) (0 0 0) (32 32 32) rotten megahealth
  99. Health box. Normally gives 25 points.
  100. Rotten box heals 5-10 points,
  101. megahealth will add 100 health, then 
  102. rot you down to your maximum health limit, 
  103. one point per second.
  104. */
  105.  
  106. float    H_ROTTEN = 1;
  107. float    H_MEGA = 2;
  108. .float    healamount, healtype;
  109. void() health_touch;
  110. void() item_megahealth_rot;
  111.  
  112. void() item_health =
  113. {    
  114.     self.touch = health_touch;
  115.  
  116.     if (self.spawnflags & H_ROTTEN)
  117.     {
  118.         precache_model("maps/b_bh10.bsp");
  119.  
  120.         precache_sound("items/r_item1.wav");
  121.         setmodel(self, "maps/b_bh10.bsp");
  122.         self.noise = "items/r_item1.wav";
  123.         self.healamount = 15;
  124.         self.healtype = 0;
  125.     }
  126.     else
  127.     if (self.spawnflags & H_MEGA)
  128.     {
  129.         precache_model("maps/b_bh100.bsp");
  130.         precache_sound("items/r_item2.wav");
  131.         setmodel(self, "maps/b_bh100.bsp");
  132.         self.noise = "items/r_item2.wav";
  133.         self.healamount = 100;
  134.         self.healtype = 2;
  135.     }
  136.     else
  137.     {
  138.         precache_model("maps/b_bh25.bsp");
  139.         precache_sound("items/health1.wav");
  140.         setmodel(self, "maps/b_bh25.bsp");
  141.         self.noise = "items/health1.wav";
  142.         self.healamount = 25;
  143.         self.healtype = 1;
  144.     }
  145.     setsize (self, '0 0 0', '32 32 56');
  146.     StartItem ();
  147. };
  148.  
  149.  
  150. void() health_touch =
  151. {
  152.     local    float amount;
  153.     local    string    s;
  154.     
  155.     if (other.classname != "player")
  156.         return;
  157.     
  158.     if (self.healtype == 2) // Megahealth?  Ignore max_health...
  159.     {
  160.         if (other.health >= 250)
  161.             return;
  162.         if (!T_Heal(other, self.healamount, 1))
  163.             return;
  164.     }
  165.     else
  166.     {
  167.         if (!T_Heal(other, self.healamount, 0))
  168.             return;
  169.     }
  170.     
  171.     sprint(other, "You receive ");
  172.     s = ftos(self.healamount);
  173.     sprint(other, s);
  174.     sprint(other, " health\n");
  175.     
  176. // health touch sound
  177.     sound(other, CHAN_ITEM, self.noise, 1, ATTN_NORM);
  178.  
  179.     stuffcmd (other, "bf\n");
  180.     
  181.     self.model = string_null;
  182.     self.solid = SOLID_NOT;
  183.  
  184.     // Megahealth = rot down the player's super health
  185.     if (self.healtype == 2)
  186.     {
  187.         other.items = other.items | IT_SUPERHEALTH;
  188.         self.nextthink = time + 5;
  189.         self.think = item_megahealth_rot;
  190.         self.owner = other;
  191.     }
  192.     else
  193.     {
  194.         if (deathmatch != 2)        // deathmatch 2 is the silly old rules
  195.         {
  196.             if (deathmatch)
  197.                 self.nextthink = time + 20;
  198.             self.think = SUB_regen;
  199.         }
  200.     }
  201.     
  202.     activator = other;
  203.     SUB_UseTargets();                // fire all targets / killtargets
  204. };    
  205.  
  206. void() item_megahealth_rot =
  207. {
  208.     other = self.owner;
  209.     
  210.     if (other.health > other.max_health)
  211.     {
  212.         other.health = other.health - 1;
  213.         self.nextthink = time + 1;
  214.         return;
  215.     }
  216.  
  217. // it is possible for a player to die and respawn between rots, so don't
  218. // just blindly subtract the flag off
  219.     other.items = other.items - (other.items & IT_SUPERHEALTH);
  220.     
  221.     if (deathmatch == 1)    // deathmatch 2 is silly old rules
  222.     {
  223.         self.nextthink = time + 20;
  224.         self.think = SUB_regen;
  225.     }
  226. };
  227.  
  228. /*
  229. ===============================================================================
  230.  
  231. ARMOR
  232.  
  233. ===============================================================================
  234. */
  235.  
  236. void() armor_touch;
  237.  
  238. void() armor_touch =
  239. {
  240.     local    float    type, value, bit;
  241.     
  242.     if (other.health <= 0)
  243.         return;
  244.     if (other.classname != "player")
  245.         return;
  246.  
  247.     if (self.classname == "item_armor1")
  248.     {
  249.         type = 0.3;
  250.         value = 100;
  251.         bit = IT_ARMOR1;
  252.     }
  253.     if (self.classname == "item_armor2")
  254.     {
  255.         type = 0.6;
  256.         value = 150;
  257.         bit = IT_ARMOR2;
  258.     }
  259.     if (self.classname == "item_armorInv")
  260.     {
  261.         type = 0.8;
  262.         value = 200;
  263.         bit = IT_ARMOR3;
  264.     }
  265.     if (other.armortype*other.armorvalue >= type*value)
  266.         return;
  267.         
  268.     other.armortype = type;
  269.     other.armorvalue = value;
  270.     other.items = other.items - (other.items & (IT_ARMOR1 | IT_ARMOR2 | IT_ARMOR3)) + bit;
  271.  
  272.     self.solid = SOLID_NOT;
  273.     self.model = string_null;
  274.     if (deathmatch == 1)
  275.         self.nextthink = time + 20;
  276.     self.think = SUB_regen;
  277.  
  278.     sprint(other, "You got armor\n");
  279. // armor touch sound
  280.     sound(other, CHAN_ITEM, "items/armor1.wav", 1, ATTN_NORM);
  281.     stuffcmd (other, "bf\n");
  282.     
  283.     activator = other;
  284.     SUB_UseTargets();                // fire all targets / killtargets
  285. };
  286.  
  287.  
  288. /*QUAKED item_armor1 (0 .5 .8) (-16 -16 0) (16 16 32)
  289. */
  290.  
  291. void() item_armor1 =
  292. {
  293.     self.touch = armor_touch;
  294.     precache_model ("progs/armor.mdl");
  295.     setmodel (self, "progs/armor.mdl");
  296.     self.skin = 0;
  297.     setsize (self, '-16 -16 0', '16 16 56');
  298.     StartItem ();
  299. };
  300.  
  301. /*QUAKED item_armor2 (0 .5 .8) (-16 -16 0) (16 16 32)
  302. */
  303.  
  304. void() item_armor2 =
  305. {
  306.     self.touch = armor_touch;
  307.     precache_model ("progs/armor.mdl");
  308.     setmodel (self, "progs/armor.mdl");
  309.     self.skin = 1;
  310.     setsize (self, '-16 -16 0', '16 16 56');
  311.     StartItem ();
  312. };
  313.  
  314. /*QUAKED item_armorInv (0 .5 .8) (-16 -16 0) (16 16 32)
  315. */
  316.  
  317. void() item_armorInv =
  318. {
  319.     self.touch = armor_touch;
  320.     precache_model ("progs/armor.mdl");
  321.     setmodel (self, "progs/armor.mdl");
  322.     self.skin = 2;
  323.     setsize (self, '-16 -16 0', '16 16 56');
  324.     StartItem ();
  325. };
  326.  
  327. /*
  328. ===============================================================================
  329.  
  330. WEAPONS
  331.  
  332. ===============================================================================
  333. */
  334.  
  335. void() bound_other_ammo =
  336. {
  337.     if (other.ammo_shells > 100)
  338.         other.ammo_shells = 100;
  339.     if (other.ammo_nails > 200)
  340.         other.ammo_nails = 200;
  341.     if (other.ammo_rockets > 100)
  342.         other.ammo_rockets = 100;        
  343.     if (other.ammo_cells > 100)
  344.         other.ammo_cells = 100;        
  345. };
  346.  
  347.  
  348. float(float w) RankForWeapon =
  349. {
  350.     if (w == IT_LIGHTNING)
  351.         return 1;
  352.     if (w == IT_ROCKET_LAUNCHER)
  353.         return 2;
  354.     if (w == IT_SUPER_NAILGUN)
  355.         return 3;
  356.     if (w == IT_GRENADE_LAUNCHER)
  357.         return 4;
  358.     if (w == IT_SUPER_SHOTGUN)
  359.         return 5;
  360.     if (w == IT_NAILGUN)
  361.         return 6;
  362.     return 7;
  363. };
  364.  
  365. /*
  366. =============
  367. Deathmatch_Weapon
  368.  
  369. Deathmatch weapon change rules for picking up a weapon
  370.  
  371. .float        ammo_shells, ammo_nails, ammo_rockets, ammo_cells;
  372. =============
  373. */
  374. void(float old, float new) Deathmatch_Weapon =
  375. {
  376.     local float or, nr;
  377.  
  378. // change self.weapon if desired
  379.     or = RankForWeapon (self.weapon);
  380.     nr = RankForWeapon (new);
  381.     if ( nr < or )
  382.         self.weapon = new;
  383. };
  384.  
  385. /*
  386. =============
  387. weapon_touch
  388. =============
  389. */
  390. float() W_BestWeapon;
  391.  
  392. void() weapon_touch =
  393. {
  394.     local    float    hadammo, best, new, old;
  395.     local    entity    stemp;
  396.     local    float    leave;
  397.  
  398.     if (!(other.flags & FL_CLIENT))
  399.         return;
  400.  
  401. // if the player was using his best weapon, change up to the new one if better        
  402.     stemp = self;
  403.     self = other;
  404.     best = W_BestWeapon();
  405.     self = stemp;
  406.  
  407.     if (deathmatch == 2 || coop)
  408.         leave = 1;
  409.     else
  410.         leave = 0;
  411.     
  412.     if (self.classname == "weapon_nailgun")
  413.     {
  414.         if (leave && (other.items & IT_NAILGUN) )
  415.             return;
  416.         hadammo = other.ammo_nails;            
  417.         new = IT_NAILGUN;
  418.         other.ammo_nails = other.ammo_nails + 30;
  419.     }
  420.     else if (self.classname == "weapon_supernailgun")
  421.     {
  422.         if (leave && (other.items & IT_SUPER_NAILGUN) )
  423.             return;
  424.         hadammo = other.ammo_rockets;            
  425.         new = IT_SUPER_NAILGUN;
  426.         other.ammo_nails = other.ammo_nails + 30;
  427.     }
  428.     else if (self.classname == "weapon_supershotgun")
  429.     {
  430.         if (leave && (other.items & IT_SUPER_SHOTGUN) )
  431.             return;
  432.         hadammo = other.ammo_rockets;            
  433.         new = IT_SUPER_SHOTGUN;
  434.         other.ammo_shells = other.ammo_shells + 5;
  435.     }
  436.     else if (self.classname == "weapon_rocketlauncher")
  437.     {
  438.         if (leave && (other.items & IT_ROCKET_LAUNCHER) )
  439.             return;
  440.         hadammo = other.ammo_rockets;            
  441.         new = IT_ROCKET_LAUNCHER;
  442.         other.ammo_rockets = other.ammo_rockets + 5;
  443.     }
  444.     else if (self.classname == "weapon_grenadelauncher")
  445.     {
  446.         if (leave && (other.items & IT_GRENADE_LAUNCHER) )
  447.             return;
  448.         hadammo = other.ammo_rockets;            
  449.         new = IT_GRENADE_LAUNCHER;
  450.         other.ammo_rockets = other.ammo_rockets + 5;
  451.     }
  452.     else if (self.classname == "weapon_lightning")
  453.     {
  454.         if (leave && (other.items & IT_LIGHTNING) )
  455.             return;
  456.         hadammo = other.ammo_rockets;            
  457.         new = IT_LIGHTNING;
  458.         other.ammo_cells = other.ammo_cells + 15;
  459.     }
  460.     else
  461.         objerror ("weapon_touch: unknown classname");
  462.  
  463.     sprint (other, "You got the ");
  464.     sprint (other, self.netname);
  465.     sprint (other, "\n");
  466. // weapon touch sound
  467.     sound (other, CHAN_ITEM, "weapons/pkup.wav", 1, ATTN_NORM);
  468.     stuffcmd (other, "bf\n");
  469.  
  470.     bound_other_ammo ();
  471.  
  472. // change to the weapon
  473.     old = other.items;
  474.     other.items = other.items | new;
  475.     
  476.     stemp = self;
  477.     self = other;
  478.  
  479.     if (!deathmatch)
  480.         self.weapon = new;
  481.     else
  482.         Deathmatch_Weapon (old, new);
  483.  
  484.     W_SetCurrentAmmo();
  485.  
  486.     self = stemp;
  487.  
  488.     if (leave)
  489.         return;
  490.  
  491. // remove it in single player, or setup for respawning in deathmatch
  492.     self.model = string_null;
  493.     self.solid = SOLID_NOT;
  494.     if (deathmatch == 1)
  495.         self.nextthink = time + 30;
  496.     self.think = SUB_regen;
  497.     
  498.     activator = other;
  499.     SUB_UseTargets();                // fire all targets / killtargets
  500. };
  501.  
  502.  
  503. /*QUAKED weapon_supershotgun (0 .5 .8) (-16 -16 0) (16 16 32)
  504. */
  505.  
  506. void() weapon_supershotgun =
  507. {
  508.     precache_model ("progs/g_shot.mdl");
  509.     setmodel (self, "progs/g_shot.mdl");
  510.     self.weapon = IT_SUPER_SHOTGUN;
  511.     self.netname = "Double-barrelled Shotgun";
  512.     self.touch = weapon_touch;
  513.     setsize (self, '-16 -16 0', '16 16 56');
  514.     StartItem ();
  515. };
  516.  
  517. /*QUAKED weapon_nailgun (0 .5 .8) (-16 -16 0) (16 16 32)
  518. */
  519.  
  520. void() weapon_nailgun =
  521. {
  522.     precache_model ("progs/g_nail.mdl");
  523.     setmodel (self, "progs/g_nail.mdl");
  524.     self.weapon = IT_NAILGUN;
  525.     self.netname = "nailgun";
  526.     self.touch = weapon_touch;
  527.     setsize (self, '-16 -16 0', '16 16 56');
  528.     StartItem ();
  529. };
  530.  
  531. /*QUAKED weapon_supernailgun (0 .5 .8) (-16 -16 0) (16 16 32)
  532. */
  533.  
  534. void() weapon_supernailgun =
  535. {
  536.     precache_model ("progs/g_nail2.mdl");
  537.     setmodel (self, "progs/g_nail2.mdl");
  538.     self.weapon = IT_SUPER_NAILGUN;
  539.     self.netname = "Super Nailgun";
  540.     self.touch = weapon_touch;
  541.     setsize (self, '-16 -16 0', '16 16 56');
  542.     StartItem ();
  543. };
  544.  
  545. /*QUAKED weapon_grenadelauncher (0 .5 .8) (-16 -16 0) (16 16 32)
  546. */
  547.  
  548. void() weapon_grenadelauncher =
  549. {
  550.     precache_model ("progs/g_rock.mdl");
  551.     setmodel (self, "progs/g_rock.mdl");
  552.     self.weapon = 3;
  553.     self.netname = "Grenade Launcher";
  554.     self.touch = weapon_touch;
  555.     setsize (self, '-16 -16 0', '16 16 56');
  556.     StartItem ();
  557. };
  558.  
  559. /*QUAKED weapon_rocketlauncher (0 .5 .8) (-16 -16 0) (16 16 32)
  560. */
  561.  
  562. void() weapon_rocketlauncher =
  563. {
  564.     precache_model ("progs/g_rock2.mdl");
  565.     setmodel (self, "progs/g_rock2.mdl");
  566.     self.weapon = 3;
  567.     self.netname = "Rocket Launcher";
  568.     self.touch = weapon_touch;
  569.     setsize (self, '-16 -16 0', '16 16 56');
  570.     StartItem ();
  571. };
  572.  
  573.  
  574. /*QUAKED weapon_lightning (0 .5 .8) (-16 -16 0) (16 16 32)
  575. */
  576.  
  577. void() weapon_lightning =
  578. {
  579.     precache_model ("progs/g_light.mdl");
  580.     setmodel (self, "progs/g_light.mdl");
  581.     self.weapon = 3;
  582.     self.netname = "Thunderbolt";
  583.     self.touch = weapon_touch;
  584.     setsize (self, '-16 -16 0', '16 16 56');
  585.     StartItem ();
  586. };
  587.  
  588.  
  589. /*
  590. ===============================================================================
  591.  
  592. AMMO
  593.  
  594. ===============================================================================
  595. */
  596.  
  597. void() ammo_touch =
  598. {
  599. local entity    stemp;
  600. local float        best;
  601.  
  602.     if (other.classname != "player")
  603.         return;
  604.     if (other.health <= 0)
  605.         return;
  606.  
  607. // if the player was using his best weapon, change up to the new one if better        
  608.     stemp = self;
  609.     self = other;
  610.     best = W_BestWeapon();
  611.     self = stemp;
  612.  
  613.  
  614. // shotgun
  615.     if (self.weapon == 1)
  616.     {
  617.         if (other.ammo_shells >= 100)
  618.             return;
  619.         other.ammo_shells = other.ammo_shells + self.aflag;
  620.     }
  621.  
  622. // spikes
  623.     if (self.weapon == 2)
  624.     {
  625.         if (other.ammo_nails >= 200)
  626.             return;
  627.         other.ammo_nails = other.ammo_nails + self.aflag;
  628.     }
  629.  
  630. //    rockets
  631.     if (self.weapon == 3)
  632.     {
  633.         if (other.ammo_rockets >= 100)
  634.             return;
  635.         other.ammo_rockets = other.ammo_rockets + self.aflag;
  636.     }
  637.  
  638. //    cells
  639.     if (self.weapon == 4)
  640.     {
  641.         if (other.ammo_cells >= 100)
  642.             return;
  643.         other.ammo_cells = other.ammo_cells + self.aflag;
  644.     }
  645.  
  646.     bound_other_ammo ();
  647.     
  648.     sprint (other, "You got the ");
  649.     sprint (other, self.netname);
  650.     sprint (other, "\n");
  651. // ammo touch sound
  652.     sound (other, CHAN_ITEM, "weapons/lock4.wav", 1, ATTN_NORM);
  653.     stuffcmd (other, "bf\n");
  654.  
  655. // change to a better weapon if appropriate
  656.  
  657.     if ( other.weapon == best )
  658.     {
  659.         stemp = self;
  660.         self = other;
  661.         self.weapon = W_BestWeapon();
  662.         W_SetCurrentAmmo ();
  663.         self = stemp;
  664.     }
  665.  
  666. // if changed current ammo, update it
  667.     stemp = self;
  668.     self = other;
  669.     W_SetCurrentAmmo();
  670.     self = stemp;
  671.  
  672. // remove it in single player, or setup for respawning in deathmatch
  673.     self.model = string_null;
  674.     self.solid = SOLID_NOT;
  675.     if (deathmatch == 1)
  676.         self.nextthink = time + 30;
  677.     self.think = SUB_regen;
  678.  
  679.     activator = other;
  680.     SUB_UseTargets();                // fire all targets / killtargets
  681. };
  682.  
  683.  
  684.  
  685.  
  686. float WEAPON_BIG2 = 1;
  687.  
  688. /*QUAKED item_shells (0 .5 .8) (0 0 0) (32 32 32) big
  689. */
  690.  
  691. void() item_shells =
  692. {
  693.     self.touch = ammo_touch;
  694.  
  695.     if (self.spawnflags & WEAPON_BIG2)
  696.     {
  697.         precache_model ("maps/b_shell1.bsp");
  698.         setmodel (self, "maps/b_shell1.bsp");
  699.         self.aflag = 40;
  700.     }
  701.     else
  702.     {
  703.         precache_model ("maps/b_shell0.bsp");
  704.         setmodel (self, "maps/b_shell0.bsp");
  705.         self.aflag = 20;
  706.     }
  707.     self.weapon = 1;
  708.     self.netname = "shells";
  709.     setsize (self, '0 0 0', '32 32 56');
  710.     StartItem ();
  711. };
  712.  
  713. /*QUAKED item_spikes (0 .5 .8) (0 0 0) (32 32 32) big
  714. */
  715.  
  716. void() item_spikes =
  717. {
  718.     self.touch = ammo_touch;
  719.  
  720.     if (self.spawnflags & WEAPON_BIG2)
  721.     {
  722.         precache_model ("maps/b_nail1.bsp");
  723.         setmodel (self, "maps/b_nail1.bsp");
  724.         self.aflag = 50;
  725.     }
  726.     else
  727.     {
  728.         precache_model ("maps/b_nail0.bsp");
  729.         setmodel (self, "maps/b_nail0.bsp");
  730.         self.aflag = 25;
  731.     }
  732.     self.weapon = 2;
  733.     self.netname = "nails";
  734.     setsize (self, '0 0 0', '32 32 56');
  735.     StartItem ();
  736. };
  737.  
  738. /*QUAKED item_rockets (0 .5 .8) (0 0 0) (32 32 32) big
  739. */
  740.  
  741. void() item_rockets =
  742. {
  743.     self.touch = ammo_touch;
  744.  
  745.     if (self.spawnflags & WEAPON_BIG2)
  746.     {
  747.         precache_model ("maps/b_rock1.bsp");
  748.         setmodel (self, "maps/b_rock1.bsp");
  749.         self.aflag = 10;
  750.     }
  751.     else
  752.     {
  753.         precache_model ("maps/b_rock0.bsp");
  754.         setmodel (self, "maps/b_rock0.bsp");
  755.         self.aflag = 5;
  756.     }
  757.     self.weapon = 3;
  758.     self.netname = "rockets";
  759.     setsize (self, '0 0 0', '32 32 56');
  760.     StartItem ();
  761. };
  762.  
  763.  
  764. /*QUAKED item_cells (0 .5 .8) (0 0 0) (32 32 32) big
  765. */
  766.  
  767. void() item_cells =
  768. {
  769.     self.touch = ammo_touch;
  770.  
  771.     if (self.spawnflags & WEAPON_BIG2)
  772.     {
  773.         precache_model ("maps/b_batt1.bsp");
  774.         setmodel (self, "maps/b_batt1.bsp");
  775.         self.aflag = 12;
  776.     }
  777.     else
  778.     {
  779.         precache_model ("maps/b_batt0.bsp");
  780.         setmodel (self, "maps/b_batt0.bsp");
  781.         self.aflag = 6;
  782.     }
  783.     self.weapon = 4;
  784.     self.netname = "cells";
  785.     setsize (self, '0 0 0', '32 32 56');
  786.     StartItem ();
  787. };
  788.  
  789.  
  790. /*QUAKED item_weapon (0 .5 .8) (0 0 0) (32 32 32) shotgun rocket spikes big
  791. DO NOT USE THIS!!!! IT WILL BE REMOVED!
  792. */
  793.  
  794. float WEAPON_SHOTGUN = 1;
  795. float WEAPON_ROCKET = 2;
  796. float WEAPON_SPIKES = 4;
  797. float WEAPON_BIG = 8;
  798. void() item_weapon =
  799. {
  800.     self.touch = ammo_touch;
  801.  
  802.     if (self.spawnflags & WEAPON_SHOTGUN)
  803.     {
  804.         if (self.spawnflags & WEAPON_BIG)
  805.         {
  806.             precache_model ("maps/b_shell1.bsp");
  807.             setmodel (self, "maps/b_shell1.bsp");
  808.             self.aflag = 40;
  809.         }
  810.         else
  811.         {
  812.             precache_model ("maps/b_shell0.bsp");
  813.             setmodel (self, "maps/b_shell0.bsp");
  814.             self.aflag = 20;
  815.         }
  816.         self.weapon = 1;
  817.         self.netname = "shells";
  818.     }
  819.  
  820.     if (self.spawnflags & WEAPON_SPIKES)
  821.     {
  822.         if (self.spawnflags & WEAPON_BIG)
  823.         {
  824.             precache_model ("maps/b_nail1.bsp");
  825.             setmodel (self, "maps/b_nail1.bsp");
  826.             self.aflag = 40;
  827.         }
  828.         else
  829.         {
  830.             precache_model ("maps/b_nail0.bsp");
  831.             setmodel (self, "maps/b_nail0.bsp");
  832.             self.aflag = 20;
  833.         }
  834.         self.weapon = 2;
  835.         self.netname = "spikes";
  836.     }
  837.  
  838.     if (self.spawnflags & WEAPON_ROCKET)
  839.     {
  840.         if (self.spawnflags & WEAPON_BIG)
  841.         {
  842.             precache_model ("maps/b_rock1.bsp");
  843.             setmodel (self, "maps/b_rock1.bsp");
  844.             self.aflag = 10;
  845.         }
  846.         else
  847.         {
  848.             precache_model ("maps/b_rock0.bsp");
  849.             setmodel (self, "maps/b_rock0.bsp");
  850.             self.aflag = 5;
  851.         }
  852.         self.weapon = 3;
  853.         self.netname = "rockets";
  854.     }
  855.     
  856.     setsize (self, '0 0 0', '32 32 56');
  857.     StartItem ();
  858. };
  859.  
  860.  
  861. /*
  862. ===============================================================================
  863.  
  864. KEYS
  865.  
  866. ===============================================================================
  867. */
  868.  
  869. void() key_touch =
  870. {
  871. local entity    stemp;
  872. local float        best;
  873.  
  874.     if (other.classname != "player")
  875.         return;
  876.     if (other.health <= 0)
  877.         return;
  878.     if (other.items & self.items)
  879.         return;
  880.  
  881.     sprint (other, "You got the ");
  882.     sprint (other, self.netname);
  883.     sprint (other,"\n");
  884.  
  885.     sound (other, CHAN_ITEM, self.noise, 1, ATTN_NORM);
  886.     stuffcmd (other, "bf\n");
  887.     other.items = other.items | self.items;
  888.  
  889.     if (!coop)
  890.     {    
  891.         self.solid = SOLID_NOT;
  892.         self.model = string_null;
  893.     }
  894.  
  895.     activator = other;
  896.     SUB_UseTargets();                // fire all targets / killtargets
  897. };
  898.  
  899.  
  900. void() key_setsounds =
  901. {
  902.     if (world.worldtype == 0)
  903.     {
  904.         precache_sound ("misc/medkey.wav");
  905.         self.noise = "misc/medkey.wav";
  906.     }
  907.     if (world.worldtype == 1)
  908.     {
  909.         precache_sound ("misc/runekey.wav");
  910.         self.noise = "misc/runekey.wav";
  911.     }
  912.     if (world.worldtype == 2)
  913.     {
  914.         precache_sound2 ("misc/basekey.wav");
  915.         self.noise = "misc/basekey.wav";
  916.     }
  917. };
  918.  
  919. /*QUAKED item_key1 (0 .5 .8) (-16 -16 -24) (16 16 32)
  920. SILVER key
  921. In order for keys to work
  922. you MUST set your maps
  923. worldtype to one of the
  924. following:
  925. 0: medieval
  926. 1: metal
  927. 2: base
  928. */
  929.  
  930. void() item_key1 =
  931. {
  932.     if (world.worldtype == 0)
  933.     {
  934.         precache_model ("progs/w_s_key.mdl");
  935.         setmodel (self, "progs/w_s_key.mdl");
  936.         self.netname = "silver key";
  937.     }
  938.     else if (world.worldtype == 1)
  939.     {
  940.         precache_model ("progs/m_s_key.mdl");
  941.         setmodel (self, "progs/m_s_key.mdl");
  942.         self.netname = "silver runekey";
  943.     }
  944.     else if (world.worldtype == 2)
  945.     {
  946.         precache_model2 ("progs/b_s_key.mdl");
  947.         setmodel (self, "progs/b_s_key.mdl");
  948.         self.netname = "silver keycard";
  949.     }
  950.     key_setsounds();
  951.     self.touch = key_touch;
  952.     self.items = IT_KEY1;
  953.     setsize (self, '-16 -16 -24', '16 16 32');
  954.     StartItem ();
  955. };
  956.  
  957. /*QUAKED item_key2 (0 .5 .8) (-16 -16 -24) (16 16 32)
  958. GOLD key
  959. In order for keys to work
  960. you MUST set your maps
  961. worldtype to one of the
  962. following:
  963. 0: medieval
  964. 1: metal
  965. 2: base
  966. */
  967.  
  968. void() item_key2 =
  969. {
  970.     if (world.worldtype == 0)
  971.     {
  972.         precache_model ("progs/w_g_key.mdl");
  973.         setmodel (self, "progs/w_g_key.mdl");
  974.         self.netname = "gold key";
  975.     }
  976.     if (world.worldtype == 1)
  977.     {
  978.         precache_model ("progs/m_g_key.mdl");
  979.         setmodel (self, "progs/m_g_key.mdl");
  980.         self.netname = "gold runekey";
  981.     }
  982.     if (world.worldtype == 2)
  983.     {
  984.         precache_model2 ("progs/b_g_key.mdl");
  985.         setmodel (self, "progs/b_g_key.mdl");
  986.         self.netname = "gold keycard";
  987.     }
  988.     key_setsounds();
  989.     self.touch = key_touch;
  990.     self.items = IT_KEY2;
  991.     setsize (self, '-16 -16 -24', '16 16 32');
  992.     StartItem ();
  993. };
  994.  
  995.  
  996.  
  997. /*
  998. ===============================================================================
  999.  
  1000. END OF LEVEL RUNES
  1001.  
  1002. ===============================================================================
  1003. */
  1004.  
  1005. void() sigil_touch =
  1006. {
  1007. local entity    stemp;
  1008. local float        best;
  1009.  
  1010.     if (other.classname != "player")
  1011.         return;
  1012.     if (other.health <= 0)
  1013.         return;
  1014.  
  1015.     centerprint (other, "You got the rune!");
  1016.  
  1017.     sound (other, CHAN_ITEM, self.noise, 1, ATTN_NORM);
  1018.     stuffcmd (other, "bf\n");
  1019.     self.solid = SOLID_NOT;
  1020.     self.model = string_null;
  1021.     serverflags = serverflags | (self.spawnflags & 15);
  1022.     self.classname = "";        // so rune doors won't find it
  1023.     
  1024.     activator = other;
  1025.     SUB_UseTargets();                // fire all targets / killtargets
  1026. };
  1027.  
  1028.  
  1029. /*QUAKED item_sigil (0 .5 .8) (-16 -16 -24) (16 16 32) E1 E2 E3 E4
  1030. End of level sigil, pick up to end episode and return to jrstart.
  1031. */
  1032.  
  1033. void() item_sigil =
  1034. {
  1035.     if (!self.spawnflags)
  1036.         objerror ("no spawnflags");
  1037.  
  1038.     precache_sound ("misc/runekey.wav");
  1039.     self.noise = "misc/runekey.wav";
  1040.  
  1041.     if (self.spawnflags & 1)
  1042.     {
  1043.         precache_model ("progs/end1.mdl");
  1044.         setmodel (self, "progs/end1.mdl");
  1045.     }
  1046.     if (self.spawnflags & 2)
  1047.     {
  1048.         precache_model2 ("progs/end2.mdl");
  1049.         setmodel (self, "progs/end2.mdl");
  1050.     }
  1051.     if (self.spawnflags & 4)
  1052.     {
  1053.         precache_model2 ("progs/end3.mdl");
  1054.         setmodel (self, "progs/end3.mdl");
  1055.     }
  1056.     if (self.spawnflags & 8)
  1057.     {
  1058.         precache_model2 ("progs/end4.mdl");
  1059.         setmodel (self, "progs/end4.mdl");
  1060.     }
  1061.     
  1062.     self.touch = sigil_touch;
  1063.     setsize (self, '-16 -16 -24', '16 16 32');
  1064.     StartItem ();
  1065. };
  1066.  
  1067. /*
  1068. ===============================================================================
  1069.  
  1070. POWERUPS
  1071.  
  1072. ===============================================================================
  1073. */
  1074.  
  1075. void() powerup_touch;
  1076.  
  1077.  
  1078. void() powerup_touch =
  1079. {
  1080. local entity    stemp;
  1081. local float        best;
  1082.  
  1083.     if (other.classname != "player")
  1084.         return;
  1085.     if (other.health <= 0)
  1086.         return;
  1087.  
  1088.     sprint (other, "You got the ");
  1089.     sprint (other, self.netname);
  1090.     sprint (other,"\n");
  1091.  
  1092.     if (deathmatch)
  1093.     {
  1094.         self.mdl = self.model;
  1095.         
  1096.         if ((self.classname == "item_artifact_invulnerability") ||
  1097.             (self.classname == "item_artifact_invisibility"))
  1098.             self.nextthink = time + 60*5;
  1099.         else
  1100.             self.nextthink = time + 60;
  1101.         
  1102.         self.think = SUB_regen;
  1103.     }    
  1104.  
  1105.     sound (other, CHAN_VOICE, self.noise, 1, ATTN_NORM);
  1106.     stuffcmd (other, "bf\n");
  1107.     self.solid = SOLID_NOT;
  1108.     other.items = other.items | self.items;
  1109.     self.model = string_null;
  1110.  
  1111. // do the apropriate action
  1112.     if (self.classname == "item_artifact_envirosuit")
  1113.     {
  1114.         other.rad_time = 1;
  1115.         other.radsuit_finished = time + 30;
  1116.     }
  1117.     
  1118.     if (self.classname == "item_artifact_invulnerability")
  1119.     {
  1120.         other.invincible_time = 1;
  1121.         other.invincible_finished = time + 30;
  1122.     }
  1123.     
  1124.     if (self.classname == "item_artifact_invisibility")
  1125.     {
  1126.         other.invisible_time = 1;
  1127.         other.invisible_finished = time + 30;
  1128.     }
  1129.  
  1130.     if (self.classname == "item_artifact_super_damage")
  1131.     {
  1132.         other.super_time = 1;
  1133.         other.super_damage_finished = time + 30;
  1134.     }    
  1135.  
  1136.     activator = other;
  1137.     SUB_UseTargets();                // fire all targets / killtargets
  1138. };
  1139.  
  1140.  
  1141.  
  1142. /*QUAKED item_artifact_invulnerability (0 .5 .8) (-16 -16 -24) (16 16 32)
  1143. Player is invulnerable for 30 seconds
  1144. */
  1145. void() item_artifact_invulnerability =
  1146. {
  1147.     self.touch = powerup_touch;
  1148.  
  1149.     precache_model ("progs/invulner.mdl");
  1150.     precache_sound ("items/protect.wav");
  1151.     precache_sound ("items/protect2.wav");
  1152.     precache_sound ("items/protect3.wav");
  1153.     self.noise = "items/protect.wav";
  1154.     setmodel (self, "progs/invulner.mdl");
  1155.     self.netname = "Pentagram of Protection";
  1156.     self.items = IT_INVULNERABILITY;
  1157.     setsize (self, '-16 -16 -24', '16 16 32');
  1158.     StartItem ();
  1159. };
  1160.  
  1161. /*QUAKED item_artifact_envirosuit (0 .5 .8) (-16 -16 -24) (16 16 32)
  1162. Player takes no damage from water or slime for 30 seconds
  1163. */
  1164. void() item_artifact_envirosuit =
  1165. {
  1166.     self.touch = powerup_touch;
  1167.  
  1168.     precache_model ("progs/suit.mdl");
  1169.     precache_sound ("items/suit.wav");
  1170.     precache_sound ("items/suit2.wav");
  1171.     self.noise = "items/suit.wav";
  1172.     setmodel (self, "progs/suit.mdl");
  1173.     self.netname = "Biosuit";
  1174.     self.items = IT_SUIT;
  1175.     setsize (self, '-16 -16 -24', '16 16 32');
  1176.     StartItem ();
  1177. };
  1178.  
  1179.  
  1180. /*QUAKED item_artifact_invisibility (0 .5 .8) (-16 -16 -24) (16 16 32)
  1181. Player is invisible for 30 seconds
  1182. */
  1183. void() item_artifact_invisibility =
  1184. {
  1185.     self.touch = powerup_touch;
  1186.  
  1187.     precache_model ("progs/invisibl.mdl");
  1188.     precache_sound ("items/inv1.wav");
  1189.     precache_sound ("items/inv2.wav");
  1190.     precache_sound ("items/inv3.wav");
  1191.     self.noise = "items/inv1.wav";
  1192.     setmodel (self, "progs/invisibl.mdl");
  1193.     self.netname = "Ring of Shadows";
  1194.     self.items = IT_INVISIBILITY;
  1195.     setsize (self, '-16 -16 -24', '16 16 32');
  1196.     StartItem ();
  1197. };
  1198.  
  1199.  
  1200. /*QUAKED item_artifact_super_damage (0 .5 .8) (-16 -16 -24) (16 16 32)
  1201. The next attack from the player will do 4x damage
  1202. */
  1203. void() item_artifact_super_damage =
  1204. {
  1205.     self.touch = powerup_touch;
  1206.  
  1207.     precache_model ("progs/quaddama.mdl");
  1208.     precache_sound ("items/damage.wav");
  1209.     precache_sound ("items/damage2.wav");
  1210.     precache_sound ("items/damage3.wav");
  1211.     self.noise = "items/damage.wav";
  1212.     setmodel (self, "progs/quaddama.mdl");
  1213.     self.netname = "Quad Damage";
  1214.     self.items = IT_QUAD;
  1215.     setsize (self, '-16 -16 -24', '16 16 32');
  1216.     StartItem ();
  1217. };
  1218.  
  1219.  
  1220.  
  1221. /*
  1222. ===============================================================================
  1223.  
  1224. PLAYER BACKPACKS
  1225.  
  1226. ===============================================================================
  1227. */
  1228.  
  1229. void() BackpackTouch =
  1230. {
  1231.     local string    s;
  1232.     local    float    best, old, new;
  1233.     local        entity    stemp;
  1234.     local    float    acount;
  1235.     
  1236.     if (other.classname != "player")
  1237.         return;
  1238.     if (other.health <= 0)
  1239.         return;
  1240.  
  1241.     acount = 0;
  1242.     sprint (other, "You get ");
  1243.  
  1244.     if (self.items)
  1245.         if ((other.items & self.items) == 0)
  1246.         {
  1247.             acount = 1;
  1248.             sprint (other, "the ");
  1249.             sprint (other, self.netname);
  1250.         }
  1251.  
  1252. // if the player was using his best weapon, change up to the new one if better        
  1253.     stemp = self;
  1254.     self = other;
  1255.     best = W_BestWeapon();
  1256.     self = stemp;
  1257.  
  1258. // change weapons
  1259.     other.ammo_shells = other.ammo_shells + self.ammo_shells;
  1260.     other.ammo_nails = other.ammo_nails + self.ammo_nails;
  1261.     other.ammo_rockets = other.ammo_rockets + self.ammo_rockets;
  1262.     other.ammo_cells = other.ammo_cells + self.ammo_cells;
  1263.  
  1264.     new = self.items;
  1265.     if (!new)
  1266.         new = other.weapon;
  1267.     old = other.items;
  1268.     other.items = other.items | new;
  1269.     
  1270.     bound_other_ammo ();
  1271.  
  1272.     if (self.ammo_shells)
  1273.     {
  1274.         if (acount)
  1275.             sprint(other, ", ");
  1276.         acount = 1;
  1277.         s = ftos(self.ammo_shells);
  1278.         sprint (other, s);
  1279.         sprint (other, " shells");
  1280.     }
  1281.     if (self.ammo_nails)
  1282.     {
  1283.         if (acount)
  1284.             sprint(other, ", ");
  1285.         acount = 1;
  1286.         s = ftos(self.ammo_nails);
  1287.         sprint (other, s);
  1288.         sprint (other, " nails");
  1289.     }
  1290.     if (self.ammo_rockets)
  1291.     {
  1292.         if (acount)
  1293.             sprint(other, ", ");
  1294.         acount = 1;
  1295.         s = ftos(self.ammo_rockets);
  1296.         sprint (other, s);
  1297.         sprint (other, " rockets");
  1298.     }
  1299.     if (self.ammo_cells)
  1300.     {
  1301.         if (acount)
  1302.             sprint(other, ", ");
  1303.         acount = 1;
  1304.         s = ftos(self.ammo_cells);
  1305.         sprint (other, s);
  1306.         sprint (other, " cells");
  1307.     }
  1308.     
  1309.     sprint (other, "\n");
  1310. // backpack touch sound
  1311.     sound (other, CHAN_ITEM, "weapons/lock4.wav", 1, ATTN_NORM);
  1312.     stuffcmd (other, "bf\n");
  1313.  
  1314. // remove the backpack, change self to the player
  1315.     remove(self);
  1316.     self = other;
  1317.  
  1318. // change to the weapon
  1319.     if (!deathmatch)
  1320.         self.weapon = new;
  1321.     else
  1322.         Deathmatch_Weapon (old, new);
  1323.  
  1324.     W_SetCurrentAmmo ();
  1325. };
  1326.  
  1327. /*
  1328. ===============
  1329. DropBackpack
  1330. ===============
  1331. */
  1332. void() DropBackpack =
  1333. {
  1334.     local entity    item;
  1335.  
  1336.     if (!(self.ammo_shells + self.ammo_nails + self.ammo_rockets + self.ammo_cells))
  1337.         return;    // nothing in it
  1338.  
  1339.     item = spawn();
  1340.     item.origin = self.origin - '0 0 24';
  1341.     
  1342.     item.items = self.weapon;
  1343.     if (item.items == IT_AXE)
  1344.         item.netname = "Axe";
  1345.     else if (item.items == IT_SHOTGUN)
  1346.         item.netname = "Shotgun";
  1347.     else if (item.items == IT_SUPER_SHOTGUN)
  1348.         item.netname = "Double-barrelled Shotgun";
  1349.     else if (item.items == IT_NAILGUN)
  1350.         item.netname = "Nailgun";
  1351.     else if (item.items == IT_SUPER_NAILGUN)
  1352.         item.netname = "Super Nailgun";
  1353.     else if (item.items == IT_GRENADE_LAUNCHER)
  1354.         item.netname = "Grenade Launcher";
  1355.     else if (item.items == IT_ROCKET_LAUNCHER)
  1356.         item.netname = "Rocket Launcher";
  1357.     else if (item.items == IT_LIGHTNING)
  1358.         item.netname = "Thunderbolt";
  1359.     else
  1360.         item.netname = "";
  1361.  
  1362.     item.ammo_shells = self.ammo_shells;
  1363.     item.ammo_nails = self.ammo_nails;
  1364.     item.ammo_rockets = self.ammo_rockets;
  1365.     item.ammo_cells = self.ammo_cells;
  1366.  
  1367.     item.velocity_z = 300;
  1368.     item.velocity_x = -100 + (random() * 200);
  1369.     item.velocity_y = -100 + (random() * 200);
  1370.     
  1371.     item.flags = FL_ITEM;
  1372.     item.solid = SOLID_TRIGGER;
  1373.     item.movetype = MOVETYPE_TOSS;
  1374.     setmodel (item, "progs/backpack.mdl");
  1375.     setsize (item, '-16 -16 0', '16 16 56');
  1376.     item.touch = BackpackTouch;
  1377.     
  1378.     item.nextthink = time + 120;    // remove after 2 minutes
  1379.     item.think = SUB_Remove;
  1380. };
  1381.